

//
//  WZUserInfoModel.m
//  weibo
//
//  Created by mac on 16/2/27.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "WZUserInfoModel.h"

@interface WZUserInfoModel ()<NSCoding>

@end

@implementation WZUserInfoModel
-(instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

+(instancetype)userInfoModelWithDic:(NSDictionary *)dic
{
    return [[self alloc]initWithDic:dic];
}
#pragma mark -- 归档
-(void)encodeWithCoder:(NSCoder *)aCoder{

    
    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeInteger:self.expires_in forKey:@"expires_in"];
    [aCoder encodeInteger:self.remind_in forKey:@"remind_in"];
    [aCoder encodeObject:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.profile_image_url forKey:@"profile_image_url"];
    [aCoder encodeObject:self.screen_name forKey:@"screen_name"];
    
}
#pragma mark -- 接档
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        
        self.expires_in = [aDecoder decodeIntegerForKey:@"expires_in"];
        
        self.remind_in = [aDecoder decodeIntegerForKey:@"remind_in"];
        
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        
        self.profile_image_url = [aDecoder decodeObjectForKey:@"profile_image_url"];
        
        self.screen_name = [aDecoder decodeObjectForKey:@"screen_name"];
    }
    
    
    return self;
    
}
#pragma mark -- 为外界提供一个存储数据的方法
-(void)saveUserPersonToDocumentWithFileName:(NSString *)fileName{
    
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    
    NSString *filePath = [documentPath stringByAppendingPathComponent:fileName];
    NSLog(@"%@",filePath);
    [NSKeyedArchiver archiveRootObject:self toFile:filePath];
}
#pragma mark -- 为外界提供一个读取储数据的方法
+(instancetype)readObjectWithFileName:(NSString *)fileName{
    
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSString *filePath = [path stringByAppendingPathComponent:fileName];
   return [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    
}
@end
